//
//  DDMenuController.m
//  DDMenuController
//
//  Copyright (c) 2011 toaast. All rights reserved.
//
//  Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
//
//  The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
//
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
//

#import "DDMenuController.h"
#import "MainViewController.h"
#import "AboutViewController.h"
#import "SuggestionViewController.h"
#import "WordSizeViewController.h"
#import "NavigationController.h"
#import "UserInfoViewController.h"

#define kMenuFullWidth 320.0f
#define kMenuDisplayedWidth 260.0f
#define kMenuOverlayWidth (self.view.bounds.size.width - kMenuDisplayedWidth)
#define kMenuBounceOffset 10.0f
#define kMenuBounceDuration .3f
#define kMenuSlideDuration .3f


@interface DDMenuController (Internal)
- (void)showShadow:(BOOL)val;
@end

@implementation DDMenuController{
    UIButton * btn;
}


@synthesize leftViewController=_left;
@synthesize rootViewController=_root;

@synthesize tap=_tap;
@synthesize pan=_pan;


- (id)initWithRootViewController:(UIViewController*)controller {
    if ((self = [super init])) {
        _root = controller;

    }
    return self;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - View lifecycle
-(void)viewWillLayoutSubviews{
    [super viewWillLayoutSubviews];

}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    if (iOS7) {
        _root.view.frame = CGRectMake(0, 20, 320, SCREEN_HEIGHT - 20);
    }
    MainViewController *mainVC = (MainViewController *)SHAREDAPPDELE.mainNav.topViewController;
    mainVC.showLeftDelegate = self;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    if (iOS7) {
        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    }
    NSLog(@"self  %@", self.view);
    
    _homeNav = ((AppDelegate *)[UIApplication sharedApplication].delegate).mainNav;
    self.leftViewController = [[LeftViewController alloc]init];
    
    self.rootType = HomeType;
    
    
    if (!_pan ) {
        UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];
        pan.delegate = (id<UIGestureRecognizerDelegate>)self;
        _pan = pan;
    }
    
    [self.view addGestureRecognizer:_pan];

    
}



- (void)viewDidUnload {
    [super viewDidUnload];
    _tap = nil;
    _pan = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    return (toInterfaceOrientation!=UIInterfaceOrientationPortrait);
}
-(BOOL)shouldAutorotate{
    return NO;
}

#pragma mark - GestureRecognizers

- (void)pan:(UIPanGestureRecognizer*)gesture {
    if (self.rootType == HomeType) {
        UINavigationController* nav = (UINavigationController*)_root;
        MainViewController* main = (MainViewController*)nav.topViewController;
        if (main.isEditing) {
            return;
        }
    }
    int flag = 0;
    if ([[[((UINavigationController *)self.rootViewController) visibleViewController] class] isSubclassOfClass:[MainViewController class]]) {
        flag = 1;
    }
    if ([[[((UINavigationController *)self.rootViewController) visibleViewController] class] isSubclassOfClass:[WordSizeViewController class]]) {
        flag = 1;
    }
    if ([[[((UINavigationController *)self.rootViewController) visibleViewController] class] isSubclassOfClass:[AboutViewController class]]) {
        flag = 1;
    }

    if ([[[((UINavigationController *)self.rootViewController) visibleViewController] class] isSubclassOfClass:[UserInfoViewController class]]) {
        flag = 1;
    }

    if ([[[((UINavigationController *)self.rootViewController) visibleViewController] class] isSubclassOfClass:[SuggestionViewController class]]) {
        flag = 1;
    }

    if (!flag) {
        return;
    }
    
    if (gesture.state == UIGestureRecognizerStateBegan) {
        [self showShadow:YES];
        _panOriginX = self.rootViewController.view.frame.origin.x;
        _panVelocity = CGPointMake(0.0f, 0.0f);
        _menuFlags.canShowLeft = YES;
        if([gesture velocityInView:self.view].x > 0) {
            _panDirection = DDMenuPanDirectionRight;
            
        } else {
            _panDirection = DDMenuPanDirectionLeft;
        }
    }
    
    if (gesture.state == UIGestureRecognizerStateChanged) {
        CGPoint velocity = [gesture velocityInView:self.view];
        if((velocity.x*_panVelocity.x + velocity.y*_panVelocity.y) < 0) {
            _panDirection = (_panDirection == DDMenuPanDirectionRight) ? DDMenuPanDirectionLeft : DDMenuPanDirectionRight;
        }
        _panVelocity = velocity;
        CGPoint translation = [gesture translationInView:self.view];
        CGRect frame = _root.view.frame;
        frame.origin.x = _panOriginX + translation.x;
        if (_menuFlags.didShowLeft) {
            frame.origin.x = MIN(frame.origin.x, kMenuDisplayedWidth);
        }
        if (_menuFlags.canShowLeft) {
            _menuFlags.showingLeftView = YES;
        } else {
            frame.origin.x = 0.0f; // ignore right view if it's not set
        }
        frame.origin.x = MAX(0, frame.origin.x);
        _root.view.frame = frame;

    } else if (gesture.state == UIGestureRecognizerStateEnded || gesture.state == UIGestureRecognizerStateCancelled) {
        
        //  Finishing moving to left, right or root view with current pan velocity        
        DDMenuPanCompletion completion = DDMenuPanCompletionRoot; // by default animate back to the root
        float offset =0;
        if (_panDirection == DDMenuPanCompletionRight) {
            offset = 70;
        }
        else{
            offset = 200;
        }
        if (_root.view.frame.origin.x > offset) {
            completion = DDMenuPanCompletionLeft;
        }
        
        CGPoint velocity = [gesture velocityInView:self.view];    
        if (velocity.x < 0.0f) {
            velocity.x = 0.0f;
        }
        BOOL bounce = (velocity.x > 800);
        CGFloat width = _root.view.frame.size.width;
        CGFloat span = (width - kMenuOverlayWidth);
        CGFloat duration = kMenuSlideDuration - .1; // default duration with 0 velocity

        
        [CATransaction begin];
        
        [CATransaction setCompletionBlock:^{
                
                if (completion == DDMenuPanCompletionLeft) {
                    [self showLeftController:YES];
                }else {
                    [self showRootController:YES];
                }
                [_root.view.layer removeAllAnimations];
                [self.view setUserInteractionEnabled:YES];
            }];
            
        CGPoint pos = _root.view.layer.position;
        CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
        
        NSMutableArray *keyTimes = [[NSMutableArray alloc] initWithCapacity:bounce ? 3 : 2];
        NSMutableArray *values = [[NSMutableArray alloc] initWithCapacity:bounce ? 3 : 2];
        NSMutableArray *timingFunctions = [[NSMutableArray alloc] initWithCapacity:bounce ? 3 : 2];
        
        [values addObject:[NSValue valueWithCGPoint:pos]];
        [timingFunctions addObject:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
        [keyTimes addObject:[NSNumber numberWithFloat:0.0f]];
        if (bounce) {
            
            duration += kMenuBounceDuration;
            [keyTimes addObject:[NSNumber numberWithFloat:1.0f - ( kMenuBounceDuration / duration)]];
            if (completion == DDMenuPanCompletionLeft) {
                
                [values addObject:[NSValue valueWithCGPoint:CGPointMake(((width/2) + span) + kMenuBounceOffset, pos.y)]];
                
            } else if (completion == DDMenuPanCompletionRight) {
                
                
            } else {
                // depending on which way we're panning add a bounce offset
                if (_panDirection == DDMenuPanDirectionLeft) {
                    [values addObject:[NSValue valueWithCGPoint:CGPointMake((width/2) - kMenuBounceOffset, pos.y)]];
                }                 
            }
            
            [timingFunctions addObject:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
        }
        if (completion == DDMenuPanCompletionLeft) {
            [values addObject:[NSValue valueWithCGPoint:CGPointMake((width/2) + span, pos.y)]];
        } else if (completion == DDMenuPanCompletionRight) {
        } else {
            [values addObject:[NSValue valueWithCGPoint:CGPointMake(width/2, pos.y)]];
        }
        
        [timingFunctions addObject:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
        [keyTimes addObject:[NSNumber numberWithFloat:1.0f]];
        
        animation.timingFunctions = timingFunctions;
        animation.keyTimes = keyTimes;
        animation.values = values;
        animation.duration = duration;
        animation.removedOnCompletion = NO;
        animation.fillMode = kCAFillModeForwards;
        [_root.view.layer addAnimation:animation forKey:nil];
        [CATransaction commit];
    
    }

}



- (void)tap:(UITapGestureRecognizer*)gesture {

    [gesture setEnabled:NO];
    [self showRootController:YES];
}

#pragma mark - UIGestureRecognizerDelegate

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
    // Check for horizontal pan gesture
    NSLog(@"手势开始");
    if (gestureRecognizer == _pan) {
        
        
        UIPanGestureRecognizer *panGesture = (UIPanGestureRecognizer*)gestureRecognizer;
        CGPoint translation = [panGesture translationInView:self.view];

        
        if ([panGesture velocityInView:self.view].x < 600 && sqrt(translation.x * translation.x) / sqrt(translation.y * translation.y) > 1 ) {
            return YES;
        } 
        return NO;
    }
    
    if (gestureRecognizer == _tap) {
        NSLog(@"轻拍手势");

        if (_root && (_menuFlags.showingRightView || _menuFlags.showingLeftView)) {
            return CGRectContainsPoint(_root.view.frame, [gestureRecognizer locationInView:self.view]);
        }
        return NO;
    }
    if ([gestureRecognizer isKindOfClass:[UIScreenEdgePanGestureRecognizer class]]) {
        NSLog(@"边缘手势");
        return YES;
    }
    return YES;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
//    id objc = SHAREDAPPDELE.mainNav.topViewController;
//    NSLog(@"%@ %@",objc,((UINavigationController *)self.rootViewController).visibleViewController);
    if (gestureRecognizer == _pan ) {
        UIPanGestureRecognizer *panGesture = (UIPanGestureRecognizer*)gestureRecognizer;
        if([panGesture velocityInView:self.view].x < 0) {
          
            return YES;
        }
    }
    if ([gestureRecognizer isKindOfClass:[UIScreenEdgePanGestureRecognizer class]]) {
        return YES;
    }
    
    return NO;
}

#pragma Internal Nav Handling 

- (void)resetNavButtons {
    if (!_root) return;
    UIViewController *topController = nil;
    if ([_root isKindOfClass:[UINavigationController class]]) {
        
        UINavigationController *navController = (UINavigationController*)_root;
        if ([[navController viewControllers] count] > 0) {
            topController = [[navController viewControllers] objectAtIndex:0];
        }
        
    } else if ([_root isKindOfClass:[UITabBarController class]]) {
        
        UITabBarController *tabController = (UITabBarController*)_root;
        topController = [tabController selectedViewController];
        
    } else {
        
        topController = _root;
        
    }

	//页面菜单
    btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(9 - SHAREDAPPDELE.extraHeight/2.0, 7, 29.5, 30.5);
    if (_rootType == HomeType || _rootType == SuggestType || _rootType == WordSizeType || _rootType == AboutType || _rootType == CollectType) {
        [btn setImage:[UIImage imageNamed:@"IconMenu.png"] forState:UIControlStateNormal];
        btn.selected = NO;
    }else{
        [btn setImage:[UIImage imageNamed:@"IconBack"] forState:UIControlStateNormal];

    }
    
    [btn addTarget:self action:@selector(showLeft:) forControlEvents:UIControlEventTouchUpInside];
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 44)];
    [view addSubview:btn];
     UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:view];
    topController.navigationItem.leftBarButtonItem = item;
    
}

- (void)showShadow:(BOOL)val {
    if (!_root) return;
    
    _root.view.layer.shadowOpacity = val ? 0.8f : 0.0f;
    if (val) {
        _root.view.layer.cornerRadius = 4.0f;
        _root.view.layer.shadowOffset = CGSizeZero;
        _root.view.layer.shadowRadius = 4.0f;
        _root.view.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.view.bounds].CGPath;
    }
    
}

#pragma mark 点击左边按钮切换试图
- (void)showHomeController:(BOOL)animated
{
    if (_rootType == HomeType) {
        [self showRootController:animated];
        NSLog(@"显示主视图");


    }
    else{
        _rootType = HomeType;
        [self setRootController:_homeNav animated:animated];
    }
}

- (void)showUserinfoController:(BOOL)animated
{
    UserInfoViewController * userinfoVC = [[UserInfoViewController alloc] init];
   
    _collectNav = [[NavigationController alloc] initWithRootViewController:userinfoVC];
    _menuFlags.didShowLeft = NO;

    if (_rootType == CollectType) {
        [self showRootController:animated];
    }
    else{
       _rootType = CollectType;
        [self setRootController:_collectNav animated:animated];
    }
}
- (void)showWordSizeController:(BOOL)animated
{
    WordSizeViewController *wordSize= [[WordSizeViewController alloc] init];
    _wordSizeNav = [[NavigationController alloc] initWithRootViewController:wordSize];
    if (_rootType == WordSizeType) {
        [self showRootController:animated];
    }
    else{
        _rootType = WordSizeType;
        [self setRootController:_wordSizeNav animated:animated];
    }

}
- (void)showAboutController:(BOOL)animated
{
    AboutViewController *about = [[AboutViewController alloc] init];
    _aboutNav = [[NavigationController alloc] initWithRootViewController:about];
    if (_rootType == AboutType) {
        [self showRootController:animated];
    }
    else{
        _rootType = AboutType;
        [self setRootController:_aboutNav animated:animated];
    }
}

- (void)showSuggestController:(BOOL)animated
{
    SuggestionViewController *suggest = [[SuggestionViewController alloc] init];
    _suggestNav = [[NavigationController alloc] initWithRootViewController:suggest];
    if (_rootType == SuggestType) {
        [self showRootController:animated];
    }
    else{
        _rootType = SuggestType;
        [self setRootController:_suggestNav animated:animated];
    }
}


- (void)showRootController:(BOOL)animated {

    if ([_root isKindOfClass:[UINavigationController class]]) {
        UINavigationController *nav = (UINavigationController*)_root;
        for (UITableView *tableView in nav.topViewController.view.subviews) {
            if ([tableView isKindOfClass:[UITableView class]]) {
                tableView.userInteractionEnabled = YES;
            }
        }
    }
    
    [_tap setEnabled:NO];
    _root.view.userInteractionEnabled = YES;

    CGRect frame = _root.view.frame;
    frame.origin.x = 0.0f;

    BOOL _enabled = [UIView areAnimationsEnabled];
    if (!animated) {
        [UIView setAnimationsEnabled:NO];
    }
    
    [UIView animateWithDuration:.3 animations:^{
        
        _root.view.frame = frame;
        
    } completion:^(BOOL finished) {
        
        _menuFlags.showingLeftView = NO;
        _menuFlags.showingRightView = NO;
        _menuFlags.didShowLeft = NO;
        _menuFlags.canShowLeft = YES;
        [self showShadow:NO];
        if (_left && _left.view.superview) {
            _left.view.hidden = YES;
        }
    }];
    
    if (!animated) {
        [UIView setAnimationsEnabled:_enabled];
    }
    
    SHAREDAPPDELE.left.show = NO;
    btn.selected = NO;//no为显示主页面

}

- (void)showLeftController:(BOOL)animated {
    if ([_root isKindOfClass:[UINavigationController class]]) {
        UINavigationController *nav = (UINavigationController*)_root;
        for (UITableView *tableView in nav.topViewController.view.subviews) {
            if ([tableView isKindOfClass:[UITableView class]]) {
                tableView.userInteractionEnabled = NO;
            }
        }
        
    }
    if (!_menuFlags.canShowLeft) {
        [self tap:_tap];
        SHAREDAPPDELE.left.show = NO;
        return;
    }

    _menuFlags.showingLeftView = YES;
    _menuFlags.didShowLeft = YES;
    SHAREDAPPDELE.left.show = YES;
    [self showShadow:YES];

    UIView *view = self.leftViewController.view;
	CGRect frame = self.view.bounds;
    NSLog(@"显示左视图");
    if (iOS7) {
        frame = CGRectMake(0, 20, self.view.bounds.size.width, SCREEN_HEIGHT-20 );
    }
    view.frame = frame;
//    _left.view.hidden = NO;
    frame = _root.view.frame;
    frame.origin.x = CGRectGetMaxX(view.frame) - (kMenuFullWidth - kMenuDisplayedWidth);
    
    BOOL _enabled = [UIView areAnimationsEnabled];
    if (!animated) {
        [UIView setAnimationsEnabled:NO];
    }
    [UIView animateWithDuration:.3 animations:^{
        _root.view.frame = frame;
        _menuFlags.canShowLeft = NO;
    } completion:^(BOOL finished) {
        [_tap setEnabled:YES];
    }];
    
    if (!animated) {
        [UIView setAnimationsEnabled:_enabled];
    }
}


- (void)setLeftViewController:(UIViewController *)leftController {
    _left = leftController;
    if ([leftController isKindOfClass:[UINavigationController class]]) {

    }
    UIView *view = self.leftViewController.view;
	CGRect frame = self.view.bounds;
    if (iOS7) {
        frame = CGRectMake(0, 20, 320, SCREEN_HEIGHT - 20);
    }
    view.frame = frame;
    [self.view insertSubview:view atIndex:0];
//    self.leftViewController.view.hidden = YES;
    [self.leftViewController viewWillAppear:NO];

    _menuFlags.canShowLeft = (_left!=nil);
}

- (void)setRootViewController:(UIViewController *)rootViewController {
    UIViewController *tempRoot = _root;
    _root = rootViewController;
    if (_root) {
        
        if (tempRoot) {
            [tempRoot.view removeFromSuperview];
            tempRoot = nil;
        }
        
        UIView *view = _root.view;
        view.frame = self.view.bounds;
        NSLog(@"点击左侧cell设置主页面显示的页面");
//        [self showRootController:YES];
        if (iOS7) {
            view.frame = CGRectMake(0, 20, 320, SCREEN_HEIGHT - 20);
        }
        [self.view addSubview:view];    
        
    } else {
        
        if (tempRoot) {
            [tempRoot.view removeFromSuperview];
            tempRoot = nil;
        }
        
    }
    [self resetNavButtons];
}

- (void)setRootController:(UIViewController *)controller animated:(BOOL)animated {
   
    if (!controller) {
        [self setRootViewController:controller];
        return;
    }
    
    if (_menuFlags.showingLeftView) {
        
        [[UIApplication sharedApplication] beginIgnoringInteractionEvents];
        
        // slide out then come back with the new root
        __block DDMenuController *selfRef = self;
        __block UIViewController *rootRef = _root;
        CGRect frame = rootRef.view.frame;
        
        [UIView animateWithDuration:.1 animations:^{
            
            rootRef.view.frame = frame;
            
        } completion:^(BOOL finished) {
            
            [[UIApplication sharedApplication] endIgnoringInteractionEvents];

            [selfRef setRootViewController:controller];
            _root.view.frame = frame;
            [selfRef showRootController:animated];
            
        }];
        
    } else {
        // just add the root and move to it if it's not center
        [self setRootViewController:controller];
        [self showRootController:animated];
    }
     
}


#pragma mark - Root Controller Navigation

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    
    NSAssert((_root!=nil), @"no root controller set");
    
    UINavigationController *navController = nil;
    
    if ([_root isKindOfClass:[UINavigationController class]]) {
    
        navController = (UINavigationController*)_root;
    
    } else if ([_root isKindOfClass:[UITabBarController class]]) {
        
        UIViewController *topController = [(UITabBarController*)_root selectedViewController];
        if ([topController isKindOfClass:[UINavigationController class]]) {
            navController = (UINavigationController*)topController;
        }
        
    } 
    
    if (navController == nil) {
       
        NSLog(@"root controller is not a navigation controller.");
        return;
    }
    
    if (_menuFlags.showingRightView) {
        
        // if we're showing the right it works a bit different, we'll make a screen shot of the menu overlay, then push, and move everything over
        __block CALayer *layer = [CALayer layer];
        CGRect layerFrame = self.view.bounds;
        layer.frame = layerFrame;
        
        UIGraphicsBeginImageContextWithOptions(layerFrame.size, YES, 0);
        CGContextRef ctx = UIGraphicsGetCurrentContext();
        [self.view.layer renderInContext:ctx];
        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        layer.contents = (id)image.CGImage;
        
        [self.view.layer addSublayer:layer];
        [navController pushViewController:viewController animated:NO];
        CGRect frame = _root.view.frame;
        frame.origin.x = frame.size.width;
        _root.view.frame = frame;
        frame.origin.x = 0.0f;
        
        CGAffineTransform currentTransform = self.view.transform;
        
        [UIView animateWithDuration:0.25f animations:^{
            
            if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) {
                
                  self.view.transform = CGAffineTransformConcat(currentTransform, CGAffineTransformMakeTranslation(0, -[[UIScreen mainScreen] applicationFrame].size.height));
                
            } else {
                
                  self.view.transform = CGAffineTransformConcat(currentTransform, CGAffineTransformMakeTranslation(-[[UIScreen mainScreen] applicationFrame].size.width, 0));
            }
          
            
        } completion:^(BOOL finished) {
            
            [self showRootController:YES];
            self.view.transform = CGAffineTransformConcat(currentTransform, CGAffineTransformMakeTranslation(0.0f, 0.0f));
            [layer removeFromSuperlayer];
            
        }];
        
    } else {
        [navController pushViewController:viewController animated:animated];
    }
}


#pragma mark - Actions 

- (void)showLeft:(UIButton *)sender {

    if (_rootType != HomeType) {
        AppDelegate *dele = (AppDelegate *)[UIApplication sharedApplication].delegate;
        self.rootViewController = dele.mainNav;
        [btn setImage:[UIImage imageNamed:@"IconMenu.png"] forState:UIControlStateNormal];
      //  btn.normalImageName = @"IconMenu.png";
        _rootType = HomeType;
    }
    sender.selected = !sender.selected;
    if (sender.selected) {
        NSLog(@"左");
        [self showLeftController:YES];
    }else{
        NSLog(@"主");
        [self showHomeController:YES];
    }
   
    
}
#pragma mark DDMenuControllerDelegate实现代理方法
-(void)reSetRootController:(UIViewController *)controller animated:(BOOL)animated{
    [self setRootController:controller animated:animated];
}

-(void)DeleShowLeft{
    [self showLeft:nil];
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter]removeObserver:self name:NightNotification object:nil];
}

@end
